<?php

class ActivityAction extends BaseAction {

    public function index() {
        $Activity = D("ActivityView");
        import("@.ORG.Page");
        $count = $Activity->count();

        $Page = new Page($count, 10);
        $show = $Page->show();

        if ($_POST['keyword']) {
            $kmap = $_POST['keyword'];
            $map['title'] = array('like', '%' . $kmap . '%');
        } elseif ($_GET['keyword']) {
            $kmap = $_GET['keyword'];
            $map['title'] = array('like', '%' . $kmap . '%');
        }
        $Page->parameter .= "keyword=" . urlencode($kmap) . "&";

        $Activity = $Activity->where($map)->order('id desc')->limit($Page->firstRow . ',' . $Page->listRows)->select();

        $new_cat = $this->_getCateOption();
        $cats = D("Categroy")->select();
        $this->assign('pages', $show);

        $this->assign("Activity", $Activity);
        
        $this->assign("cats", $new_cat);
        $this->assign("title", '活动');
        $this->display("Public:activity");
    }
    public function edit() {

        if ($_GET['id']) {
            $Activity = D("Activity")->getById($_GET['id']);

            $new_cat = $this->_getCateOption();

            $this->assign("cats", $new_cat);
            $this->assign($Activity);

            $this->display("Public:Activity");
        } else {
            $this->assign("jumpUrl", "__URL__");
            $this->error("数据不存在！");
        }
    }

    public function doedit() {
        $data = $_POST;
        $data['parameters'] = nl2br($data['parameters']);
        if (!empty($_FILES['attachment']['name']))
            $data['attachment'] = $this->_upload("Activity", true, 360, 240, true);
        $data['postdate'] = strtotime($_POST['postdate']);
        if (D("Activity")->save($data)) {
            $this->success("修改成功！");
        } else {
            $this->error("资料无改变或修改失败！");
        }
    }

    public function batch() {
        $this->_batch();
    }

}

?>